﻿using Enterprise_Get.API.Application.Commands.MainPlanToTable;
using Enterprise_Get.API.Infrastructures.Interfaces;
using MediatR;
using Return.Enum;
using SlaughterItem.Common.Infrastructures.Interfaces;
using THE_WIND_RISES.Common.Domans.BasicInformation.MainPlans;
using THE_WIND_RISES.Common.Dtos;

namespace Enterprise_Get.API.Application.Commands.MainPlan_Excel
{
    /// <summary>
    /// 将朱生产计划生成Excel表格
    /// </summary>
    public class ShowMainplanExcelHander : IRequestHandler<ShowMainPlanExcelCommand, Result>
    {
        public ShowMainplanExcelHander(IBaseRepositoryGet<Mainpalan> MainpalanRepository)
        {
            this.MainpalanRepository = MainpalanRepository;
        }

        public IBaseRepositoryGet<Mainpalan> MainpalanRepository { get; set; }
        public async Task<Result> Handle(ShowMainPlanExcelCommand request, CancellationToken cancellationToken)
        {
            var result= new Result() { Code=(int)CommonErrorCodes.Search};
            var sql = "select * from mainpalans ;";
            var list = MainpalanRepository.GetAll(sql).ToList();
            if (list != null)
            {
                result.Data = list;
                result.Code = (int)CommonErrorCodes.Success;
                return result;
            }
            else
            {
                return result;
            }
        }
    }
}
